﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using FacebookApp;

public partial class Modules_Search : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Showddl();
        }
    }

    private void Showddl()
    {
        List<Category> dt = new List<Category>();
        dt = CategoryService.Category_GetByAll();
        //ddlGroupProduct.DataSource = dt;
        //ddlGroupProduct.DataTextField = "Name";
        //ddlGroupProduct.DataValueField = "ID";
        //ddlGroupProduct.DataBind();
        ddlGroupProduct.Items.Add(new ListItem("Tất cả", "-1"));
        for (int i = 0; i < dt.Count; i++)
        {
            ddlGroupProduct.Items.Add(new ListItem(dt[i].Name.ToString(), dt[i].Id.ToString()));

        }
    }

    protected void btnSeach_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        if (!txtSearch.Text.Trim().Equals(""))
        {
            if (ddlChoose.SelectedValue == "0")
            {
                Session["flag"] = 0;
            }
            else if (ddlChoose.SelectedValue == "1")
            {
                Session["flag"] = 1;
            }
            else if (ddlChoose.SelectedValue == "2")
            {
                Session["flag"] = 2;
            }
            //else if (ddlChoose.SelectedValue == "3")
            //{
            //    Session["flag"] = 3;
            //}
            Session["keyword"] = txtSearch.Text;
        }
        if (!txtPrice1.Text.Trim().Equals(""))
        {
            string Price1 = txtPrice1.Text.Replace(".", "");
            Price1 = Price1.Replace(",", "");
            Session["Price1"] = Price1;
        }
        if (!txtPrice2.Text.Trim().Equals(""))
        {
            string Price2 = txtPrice2.Text.Replace(".", "");
            Price2 = Price2.Replace(",", "");
            Session["Price2"] = Price2;
        }        
        Session["GroupProduct"] = ddlGroupProduct.SelectedValue;
        Response.Redirect("~/Pages/Search.aspx");
    }
    
}